Page({
  data: {

  },
  onLoad: function (options) {
    this.setData({
      list: wx.getStorageSync('searchHis')
    })
  },
  onShow: function () {

  },
  search(e) {
    console.log(e);

    // this.setData({
    //   inputVal: e.detail
    // })
    if (e.detail) {
      let searchHis = wx.getStorageSync('searchHis')
      if (!searchHis) {
        searchHis = [e.detail]
      }
      if (!searchHis.includes(e.detail)) {
        searchHis.push(e.detail)
      }
      wx.setStorageSync('searchHis', searchHis)
      this.setData({
        list: searchHis
      })
    }
    let detail = e.detail;
    wx.navigateTo({ //跳转第二个页面 并把参数传递过去
        url: '/pages/Searchpage/Searchpage?placeId=' + detail + '',
      }),
      wx.showLoading({
        title: '跳转中...',
      })

    setTimeout(function () {
      wx.hideLoading()
    }, 500);
  },
  onClose(e) {
    const idx = e.currentTarget.dataset.idx
    const searchHis = this.data.list
    searchHis.splice(idx, 1)
    wx.setStorageSync('searchHis', searchHis)
    this.setData({
      list: searchHis
    })
  },
  go(e) {
    const idx = e.currentTarget.dataset.idx
    const detail = this.data.list[idx]
    wx.redirectTo({
      url: '/pages/Searchpage/Searchpage?placeId=' + detail,
    })
  }
})